package mapevents;

import gameengine.map.Map;
import gameengine.map.unit.Unit;

public final class MapAttackEvent extends AbstractMapEvent {

    private final transient AbstractMapEvent attackerEvent;
    private final transient AbstractMapEvent attackedEvent;

    public MapAttackEvent(final AbstractMapEvent attacker, final AbstractMapEvent attacked) {
        super();
        attackerEvent = attacker;
        attackedEvent = attacked;
    }

    @Override
    public MAPEVENTTYPE getType() {
        return MAPEVENTTYPE.ATTACK;
    }

    @Override
    public int getXStart() {
        return attackerEvent.getXStart();
    }

    @Override
    public int getYStart() {
        return attackerEvent.getYStart();
    }

    @Override
    public int getXTarget() {
        return attackedEvent.getXStart();
    }

    @Override
    public int getYTarget() {
        return attackedEvent.getYStart();
    }

    @Override
    public Unit getUnit() {
        return attackedEvent.getUnit();
    }

    @Override
    public Unit getAttacker() {
        return attackerEvent.getUnit();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();

        builder.append("attack ");
        builder.append(attackerEvent.getXStart()).append(" ");
        builder.append(attackerEvent.getYStart()).append(" ");
        builder.append(attackedEvent.getXStart()).append(" ");
        builder.append(attackedEvent.getYStart()).append(" ");

        return builder.toString();
    }

    @Override
    public AbstractMapEvent newMapEvent(final int xClick, final int yClick, final boolean leftClick, final Map map, final int party) {
        return getMapEvent(xClick, yClick, leftClick, map, party);
    }
}
